package com.gaogzhen.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gaogzhen.domain.SysRole;
import com.gaogzhen.mapper.SysRoleMapper;
import com.gaogzhen.service.SysRoleService;
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements SysRoleService{

    @Autowired
    private SysRoleMapper sysRoleMapper;

    @Override
    public boolean isAdminRole(Long userId) {
        // 1、通过用户Id查询角色
        String roleCode = sysRoleMapper.getRoleCodeByUserId(userId);
        // 2、判断角色是否为超级管理员
        return StringUtils.equals("ROLE_ADMIN", roleCode);

    }

    @Override
    public Page<SysRole> findByPage(Page<SysRole> page, String name) {
        return page(page, new LambdaQueryWrapper<SysRole>().like(
                StringUtils.isNotEmpty(name),
                SysRole::getName,
                name
        ));
    }
}
